package cn.wokoba.dao.mapper;


import cn.wokoba.dao.pojo.RaffleActivityOrder;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

//抽奖活动单
@Mapper
public interface RaffleActivityOrderMapper extends BaseMapper<RaffleActivityOrder> {



    @Update("        update raffle_activity_order set state = 'completed', update_time = now()\n" +
            "        where user_id = #{userId} and out_business_no = #{outBusinessNo} and state = 'wait_pay'")
    int updateOrderCompleted(RaffleActivityOrder raffleActivityOrderReq);

    @Select("select user_id, sku, activity_id, activity_name, strategy_id, order_id, order_time, total_count, day_count, month_count, pay_amount, state\n" +
            "        from raffle_activity_order\n" +
            "        where user_id = #{userId} and out_business_no = #{outBusinessNo}")
    RaffleActivityOrder queryRaffleActivityOrder(RaffleActivityOrder raffleActivityOrderReq);

    @Select("""
            select user_id, order_id, out_business_no, pay_amount
                    from raffle_activity_order
                    where user_id = #{userId} and sku = #{sku} and state = 'wait_pay' and order_time >= NOW() - INTERVAL 1 MONTH
                    limit 1""")
    RaffleActivityOrder queryUnpaidActivityOrder(RaffleActivityOrder raffleActivityOrderReq);
}
